﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using M3G;

namespace MyTestProject
{
    
    public class TestLight
    {
        [Fact]
        public void TestConstructor()
        {
            var lgh = new Light();

            Assert.Equal(Light.Directional, lgh.Mode);
            Assert.Equal(0x00ffffffu, lgh.Color);
            Assert.Equal(1.0f, lgh.Intensity);
            Assert.Equal(1.0f, lgh.ConstantAttenuation);
            Assert.Equal(0.0f, lgh.LinearAttenuation);
            Assert.Equal(0.0f, lgh.QuadraticAttenuation);
            Assert.Equal(45.0f, lgh.SpotAngle);
            Assert.Equal(0.0f, lgh.SpotExponent);
        }

        [Fact]
        public void TestSetMode () {
            var lgh = new Light ();
            lgh.Mode = Light.Omni;

            Assert.Equal (Light.Omni, lgh.Mode);
        }

        [Fact]
        public void TestSetColor()
        {
            var lgh = new Light();
            lgh.Color = 0x12345678u;
         
            Assert.Equal(0x00345678u, lgh.Color);
        }

        [Fact]
        public void TestSetIntensity(){
            var lgh = new Light();
            lgh.Intensity = 2.0f;

            Assert.Equal(2.0f, lgh.Intensity);
        }

        [Fact]
        public void TestSetAttenuation()
        {
            var lgh = new Light();
            lgh.SetAttenuation (1.0f, 2.0f, 3.0f);

            Assert.Equal(1.0f, lgh.ConstantAttenuation);
            Assert.Equal(2.0f, lgh.LinearAttenuation);
            Assert.Equal(3.0f, lgh.QuadraticAttenuation);
        }

     

        [Fact]
        public void TestSetSpot()
        {
            var lgh = new Light();

            // Set()系の関数が2つに分かれているのは珍しい
            // というかおかしい。
            lgh.SpotAngle = 60.0f;
            lgh.SpotExponent = 10.0f;

            Assert.Equal(60.0f, lgh.SpotAngle);
            Assert.Equal(10.0f, lgh.SpotExponent);
        }

        [Fact]
        public void TestDuplicate () {
            var lgh = new Light ();
            lgh.Mode = Light.Omni;
            lgh.Color = 0x12345678u;
            lgh.Intensity = 2.0f;
            lgh.SetAttenuation (1.0f, 2.0f, 3.0f);
            lgh.UserID = 100;

            var grp = new Group ();
            grp.AddChild (lgh);

            var dup = (Light)lgh.Duplicate ();

            Assert.Equal (null, dup.Parent);
            Assert.Equal (lgh.Mode, dup.Mode);
            Assert.Equal (lgh.Color, dup.Color);
            Assert.Equal (lgh.Intensity, dup.Intensity);
            Assert.Equal (lgh.ConstantAttenuation, dup.ConstantAttenuation);
            Assert.Equal (lgh.LinearAttenuation, dup.LinearAttenuation);
            Assert.Equal (lgh.QuadraticAttenuation, dup.QuadraticAttenuation);
            Assert.Equal (lgh.SpotAngle, dup.SpotAngle);
            Assert.Equal (lgh.SpotExponent, dup.SpotExponent);
            Assert.Equal (100, dup.UserID);
        }
    }
}
